package threadLearn;

/**
 * 类锁的第一种形式
 * xxx.class
 * 本质其实就是每个类的Class对象是唯一的
 * @author 12609
 *
 */
public class SynchronizedClass implements Runnable{

	static SynchronizedClass instance1 = new SynchronizedClass();
	static SynchronizedClass instance2 = new SynchronizedClass();
	
	@Override
	public void run() {
		
		
		synchronized (SynchronizedClass.class) {
			System.out.println("开始 " + Thread.currentThread().getName());
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + " 运行结束");
		}
		
	}
	public static void main(String[] args) {
		Thread t1 = new Thread(instance1);
		Thread t2 = new Thread(instance2);
		
		t1.start();
		t2.start();
		while(t1.isAlive() || t2.isAlive()) {
			
		}
		System.out.println("finished...");
		
	}
	
}
